home *** CD-ROM | disk | FTP | other *** search
-
- #include "CRect.h"
-
- #include "macros.h"
-
-
- void CRect::SetLeftTop(const CPoint pt)
- {
- fRect.left = pt.X();
- fRect.top = pt.Y();
- }
-
-
- void CRect::SetRightBottom(const CPoint pt)
- {
- fRect.right = pt.X();
- fRect.bottom = pt.Y();
- }
-
-
- void CRect::SetLeftBottom(const CPoint pt)
- {
- fRect.left = pt.X();
- fRect.bottom = pt.Y();
- }
-
-
- void CRect::SetRightTop(const CPoint pt)
- {
- fRect.right = pt.X();
- fRect.top = pt.Y();
- }
-
-
-
- void CRect::InsetBy(CPoint pt)
- {
- InsetBy(pt.X(), pt.Y());
- }
-
-
- void CRect::InsetBy(GraphicalUnit dx, GraphicalUnit dy)
- {
- fRect.left += dx;
- fRect.right -= dx;
- fRect.top += dy;
- fRect.bottom -= dy;
- }
-
-
- void CRect::OffsetBy(CPoint pt)
- {
- OffsetBy(pt.X(), pt.Y());
- }
-
-
- void CRect::OffsetBy(GraphicalUnit dx, GraphicalUnit dy)
- {
- fRect.left += dx;
- fRect.right += dx;
- fRect.top += dy;
- fRect.bottom += dy;
- }
-
-
- void CRect::OffsetTo(CPoint pt)
- {
- fRect.right = Width() + pt.X();
- fRect.bottom = Height() + pt.Y();
- }
-
-
- void CRect::OffsetTo(GraphicalUnit x, GraphicalUnit y)
- {
- fRect.right = Width() + x;
- fRect.bottom = Height() + y;
- }
-
-
-
- Boolean CRect::operator==(CRect r) const
- {
- return (Left() == r.Left()) && (Top() == r.Top()) && (Right() == r.Right()) && (Bottom() == r.Bottom());
- }
-
-
- Boolean CRect::operator!=(CRect r) const
- {
- return (Left() != r.Left()) || (Top() != r.Top()) || (Right() != r.Right()) || (Bottom() != r.Bottom());
- }
-
-
-
- CRect CRect::operator&(CRect r) const
- {
- return CRect(min(Left(), r.Left()), min(Top(), r.Top()), max(Right(), r.Right()), max(Bottom(), r.Bottom()));
- }
-
-
- CRect CRect::operator|(CRect r) const
- {
- return CRect(max(Left(), r.Left()), max(Top(), r.Top()), min(Right(), r.Right()), min(Bottom(), r.Bottom()));
- }
-
-
-
- Boolean CRect::Intersects(CRect r) const
- {
- return (r.Left() < Right()) && (r.Right() > Left()) && (r.Top() < Bottom()) && (r.Bottom() > Top());
- }
-
-
- Boolean CRect::Contains(CPoint pt) const
- {
- return (pt.X() <= Right()) && (pt.X() >= Left()) && (pt.Y() <= Bottom()) && (pt.Y() >= Top());
- }
-
-
- Boolean CRect::Contains(CRect r) const
- {
- return (r.Left() >= Left()) && (r.Right() <= Right()) && (r.Top() >= Top()) && (r.Bottom() <= Bottom());
- }
-
- void CRect::Center(CRect outsideRect, Boolean scaleIfNeeded)
- {
- CRect r(*this);
-
- if (scaleIfNeeded)
- {
-
- // make r smallest square enclosing srcRect
- if (r.Width() > r.Height())
- r.SetHeight(r.Width());
- else
- r.SetWidth(r.Height());
-
- ::MapRect((Rect*)this, r, outsideRect);
-
- // Center the theRect inside destRect (topleft's already equal)
- OffsetBy((outsideRect.Right() - Right()) / 2, (outsideRect.Bottom() - Bottom()) / 2);
- }
- else
- {
- // Center theRect uniformly inside destRect without scaling
-
- // Center the theRect inside destRect (topleft's already equal)
- fRect.left = outsideRect.Left() + r.Width() >> 1;
- fRect.right = Left() + r.Width();
- fRect.top = outsideRect.Top() + r.Height() >> 1;
- fRect.bottom = Left() + r.Height();
- }
-
- }
-
-
-